package recharge_management

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type BankListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// bank--列表
func NewBankListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BankListLogic {
	return &BankListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BankListLogic) BankList(req *types.BankListRequest) (resp *types.BankListResponse, err error) {
	rpcReq := rpc.BankListRequest{
		BankName:   req.BankName,
		CardNumber: req.CardNumber,
		CardHolder: req.CardHolder,
	}

	rpcResp, err := l.svcCtx.AssetsRpc.TenantChannel.BankList(l.ctx, &rpcReq)
	if err != nil {
		return nil, err
	}

	var records []types.Bank
	for _, record := range rpcResp.Records {
		records = append(records, types.Bank{
			Id:           record.Id,
			CreatedAt:    record.CreatedAt,
			UpdatedAt:    record.UpdatedAt,
			Code:         record.Code,
			Phone:        record.Phone,
			MinAmount:    record.MinAmount,
			MaxAmount:    record.MaxAmount,
			DailyTimes:   record.DailyTimes,
			DailyAmount:  record.DailyAmount,
			RemainTimes:  record.RemainTimes,
			RemainAmount: record.RemainAmount,
			VisionLevel:  record.VisionLevel,
			IsDisplay:    record.IsDisplay,
			CardNumber:   record.CardNumber,
			BankNickname: record.BankNickname,
			BankName:     record.BankName,
			IfscCode:     record.IfscCode,
			Email:        record.Email,
			Province:     record.Province,
			City:         record.City,
			BranchBank:   record.BranchBank,
			IsLimit:      record.IsLimit,
			CardHolder:   record.CardHolder,
			Sort:         record.Sort,
		})
	}

	return &types.BankListResponse{
		Records: records,
		Pagination: types.Pagination{
			Page: 1,
		},
		CommonResp: types.CommonResp{
			Code:    rpcResp.CommonResp.Code,
			Message: rpcResp.CommonResp.Message,
		},
	}, nil
}
